package io.wongxd.lib_downloadx

import kotlinx.coroutines.CoroutineScope
import io.wongxd.lib_downloadx.core.DownloadTask
import io.wongxd.lib_downloadx.core.DownloadParam
import io.wongxd.lib_downloadx.core.DownloadConfig

fun CoroutineScope.downloadx(
    url: String,
    saveDir: String,
    saveName: String,
    downloadConfig: DownloadConfig = DownloadConfig()
): DownloadTask {
    val downloadParam = DownloadParam(url, saveDir, saveName)
    return downloadx(downloadParam, downloadConfig)
}

fun CoroutineScope.downloadx(
    downloadParam: DownloadParam,
    downloadConfig: DownloadConfig = DownloadConfig()
): DownloadTask {
    val task = DownloadTask(this, downloadParam, downloadConfig)
    return downloadConfig.taskManager.add(task)
}

fun downloadx(
    url: String,
    saveDir: String,
    saveName: String,
    downloadConfig: DownloadConfig = DownloadConfig()
): DownloadTask {
    val downloadParam = DownloadParam(url, saveDir, saveName)
    return downloadx(downloadParam, downloadConfig)
}

fun downloadx(
    downloadParam: DownloadParam,
    downloadConfig: DownloadConfig = DownloadConfig()
): DownloadTask {
    val task = DownloadTask(param = downloadParam, config = downloadConfig)
    return downloadConfig.taskManager.add(task)
}